package com.wgts.wgts.mvp.view.activity.classification;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.mvp.view.activity.homeclasschildactivity.ShopClassChildActivity;
import com.wgts.wgts.netmodle.resp.AllClassTypeEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.ArrayList;

public class ClassificationDetailProductAdapter extends RecyclerView.Adapter<com.wgts.wgts.mvp.view.activity.classification.ClassificationDetailProductAdapter.ClassificationDetailProductViewHolder> {

    private ArrayList<AllClassTypeEntity.ChrilEntity> data;

    private Context context;

    private int secondIndex;

    public ClassificationDetailProductAdapter(Context context, ArrayList<AllClassTypeEntity.ChrilEntity> data, int secondIndex){
        this.context = context;
        this.data = data;
        this.secondIndex = secondIndex;
    }

    @NonNull
    @Override
    public ClassificationDetailProductViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ClassificationDetailProductViewHolder(LayoutInflater.from(context).inflate(R.layout.classification_detail_product_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ClassificationDetailProductViewHolder classificationDetailProductViewHolder, final int i) {
        classificationDetailProductViewHolder.tvProductName.setText(data.get(i).typeName);
        MoHuGlide.getInstance().glideImgsFormList(classificationDetailProductViewHolder.imgProduct, data.get(i).typeImage, context);
        classificationDetailProductViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShopClassChildActivity.class);
                intent.putExtra(ShopClassChildActivity.NAME, data.get(i).typeName);
                intent.putExtra(ShopClassChildActivity.ID, data.get(i).typeId);
                intent.putExtra(ShopClassChildActivity.INTO_TYPE, ShopClassChildActivity.CLASS_THREE);
                intent.putExtra(ShopClassChildActivity.SECONDTYPEID, secondIndex);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ClassificationDetailProductViewHolder extends RecyclerView.ViewHolder{
        public TextView tvProductName;
        public ImageView imgProduct;
        public View itemView;
        public ClassificationDetailProductViewHolder(@NonNull View itemView) {
            super(itemView);
            tvProductName = itemView.findViewById(R.id.tv_product);
            imgProduct = itemView.findViewById(R.id.img_product);
            this.itemView = itemView;
        }
    }

}
